package com.jml.原子引用;


import java.util.concurrent.atomic.AtomicReference;

/**
 * @author:jml
 * @date: 2019/4/29 10:59
 * @description：
 */
public class ABADemo {

    static AtomicReference<Integer> atomicReference = new AtomicReference<>(100);

    public static void main(String[] args) {
        new Thread(()->{
            atomicReference.compareAndSet(100,101);
            atomicReference.compareAndSet(101,100);
            System.out.println("完成ABA");
        },"t1").start();

        new Thread(()->{
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            atomicReference.compareAndSet(100,2019);
            System.out.println(atomicReference.get());
        },"t2").start();
    }
}
